//
//  buildViewController.m
//  finalProject
//
//  Created by iD Student on 7/30/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "buildViewController.h"

@interface buildViewController ()

@end

@implementation buildViewController
@synthesize buttonLightningTower;
@synthesize buttonWaterTower;
@synthesize buttonEarthTower;
@synthesize buttonAirTower;
@synthesize display;
@synthesize displayGold;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    displayGold.text = [NSString stringWithFormat:@"%d",gold];
    buttonLightningTower.titleLabel.textAlignment = UITextAlignmentLeft;
    [buttonLightningTower.titleLabel setLineBreakMode:UILineBreakModeCharacterWrap];
    [buttonLightningTower setTitle:@"Lightning Tower\nDamage:4 Cost:50" forState:UIControlStateNormal];
    buttonWaterTower.titleLabel.textAlignment = UITextAlignmentLeft;
    [buttonWaterTower.titleLabel setLineBreakMode:UILineBreakModeCharacterWrap];
    [buttonWaterTower setTitle:@"Water Tower\nDamage:3 Cost:125\nSlows enemies" forState:UIControlStateNormal];
    //\nSlows enemies
    buttonEarthTower.titleLabel.textAlignment = UITextAlignmentLeft;
    [buttonEarthTower.titleLabel setLineBreakMode:UILineBreakModeCharacterWrap];
    [buttonEarthTower setTitle:@"Earth Tower\nDamage:7 Cost:200" forState:UIControlStateNormal];
    //\nDeals AoE damage
    buttonAirTower.titleLabel.textAlignment = UITextAlignmentLeft;
    [buttonAirTower.titleLabel setLineBreakMode:UILineBreakModeCharacterWrap];
    [buttonAirTower setTitle:@"Air Tower\nDamage:2 Cost:100\nFast attack speed" forState:UIControlStateNormal];
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [self setButtonLightningTower:nil];
    [self setButtonWaterTower:nil];
    [self setButtonEarthTower:nil];
    [self setButtonAirTower:nil];
    [self setDisplay:nil];
    [self setDisplayGold:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)towerBuy:(id)sender {
    UIButton *button = sender;
    if (button.tag==1) {
        if (gold>=50) {
            towerType = @"lightning";
            gold -= 50;
            display.text = @" ";
            displayGold.text = [NSString stringWithFormat:@"%d",gold];
            [self dismissModalViewControllerAnimated:YES];
            build = TRUE;
        } else {
            display.text = @"Not enough gold.";
        }
    } else if (button.tag==2) {
        if (gold>=125) {
            towerType = @"water";
            gold -= 125;
            display.text = @" ";
            displayGold.text = [NSString stringWithFormat:@"%d",gold];
            [self dismissModalViewControllerAnimated:YES];
            build = TRUE;
        } else {
            display.text = @"Not enough gold.";
        }
    } else if (button.tag==3) {
        if (gold>=200) {
            towerType = @"earth";
            gold -= 200;
            display.text = @" ";
            displayGold.text = [NSString stringWithFormat:@"%d",gold];
            [self dismissModalViewControllerAnimated:YES];
            build = TRUE;
        } else {
            display.text = @"Not enough gold.";
        }
    } else if (button.tag==4) {
        if (gold>=100) {
            towerType = @"air";
            gold -= 100;
            display.text = @" ";
            displayGold.text = [NSString stringWithFormat:@"%d",gold];
            [self dismissModalViewControllerAnimated:YES];
            build = TRUE;
        } else {
            display.text = @"Not enough gold.";
        }
    } else if (button.tag==5) {
        [self dismissModalViewControllerAnimated:YES];
        display.text = @" ";
    }
}
    
@end
